home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / EXTEND5.ARJ / EXTEND.ASM next >
Assembly Source File  |  1990-11-19  |  8KB  |  212 lines

  1. ;   This is the source code for the replacement INT 21 handler EXTEND.PAS.
  2. ; This code is designed to be compiled by the TASM assembler and linked into
  3. ; the Pascal code.
  4. ;
  5. ;   This code was based upon earlier work by Randy Forgaard, Bela Lubkin and
  6. ; Kim Kokkonen.  The previous implementation was based on using the same
  7. ; technique only not using an interrupt handler.  See EXTEND.DOC for more
  8. ; information.
  9. ;
  10. ;   To compile with TASM:
  11. ;      TASM EXTEND
  12. ;
  13. ; Scott Bussinger
  14. ; Professional Practice Systems
  15. ; 110 South 131st
  16. ; Tacoma, WA  98444
  17. ; (206)531-8944
  18. ; Compuserve [72247,2671]
  19. ;
  20. COMMENT ~
  21.   ** Revision History **
  22.   1 EXTEND.ASM 9-Mar-89,`SCOTT' First version using TLIB -- Based on 3.2
  23.   2 EXTEND.ASM 19-Nov-90,`SCOTT'
  24.            Modified documentation to be less confusing
  25.   ** Revision History **
  26. ~
  27.         PUBLIC  ExtendInit,ExtendHandler
  28.  
  29. DSEG    SEGMENT WORD PUBLIC
  30.  
  31.         EXTRN   OldInt21:DWORD         ; Address of old INT 21 handler
  32.         EXTRN   PrefixSeg:WORD         ; Segment address of Pascal program's PSP
  33.  
  34. DSEG    ENDS
  35.  
  36.  
  37. CSEG    SEGMENT WORD PUBLIC
  38.  
  39.         ASSUME  CS:CSEG, DS:DSEG
  40.  
  41. ; CS relative Data Storage
  42.  
  43. HandleTable    DD ?                    ; Pointer to standard handle table in PSP
  44. IntVector      DD ?                    ; Provide CS relative storage for old INT 21 vector
  45. SaveFunction   DB ?                    ; Save DOS function number
  46. SaveHandle     DB ?                    ; Save original handle
  47. SaveLastDCB    DB ?                    ; Save original handle slot
  48.  
  49. ; Initialize a few CS relative variables
  50.  
  51. ExtendInit PROC NEAR
  52.         LES   AX,[OldInt21]            ; Get the original INT 21 vector into CS relative storage
  53.         MOV   WORD PTR CS:[IntVector],AX
  54.         MOV   WORD PTR CS:[IntVector+2],ES
  55.  
  56.         MOV   WORD PTR CS:[HandleTable],0018H ; Create a pointer to handle table in PSP
  57.         MOV   AX,[PrefixSeg]
  58.         MOV   WORD PTR CS:[HandleTable+2],AX
  59.         RET
  60.  
  61. ExtendInit ENDP
  62.  
  63.  
  64. ; Main replacement for INT 21 handler
  65.  
  66. ExtendHandler PROC FAR
  67.  
  68.         PUSH  BP                       ; Save BP
  69.  
  70.         MOV   BP,SP                    ; Make sure this call is from our program
  71.         MOV   BP,[BP+4]                ; BP = caller's CS
  72.         CMP   BP,WORD PTR CS:[HandleTable+2] ; Is the caller's CS < our PSP address
  73.         JB    IgnoreExtend
  74.         CMP   BP,DSEG                  ; Is the caller's CS < our data segment
  75.         JAE   IgnoreExtend
  76.  
  77.         POP   BP                       ; Restore BP
  78.  
  79.         CMP   AH,4BH                   ; Skip the rest of this if an EXEC function
  80.         JNE   NotEXEC
  81.  
  82. IgnoreExtend:
  83.         POP   BP                       ; Restore BP
  84.         JMP   CS:[IntVector]           ; Go to original handler
  85.  
  86. NotEXEC:
  87.         CMP   AH,46H                   ; Function $46 is only partially supported
  88.         JNE   ValidFunction
  89.         CMP   CL,4                     ; Permit FORCEDUP if it's a standard handle
  90.         JBE   ValidFunction
  91.  
  92. NotSupported:
  93.         MOV   AX,6                     ; Tell the user it's an invalid handle
  94.         STC                            ; Signal an error
  95.         JMP   ReturnToTurbo
  96.  
  97. ValidFunction:
  98.         PUSH  DS                       ; Set up pointer to handle table
  99.         PUSH  CX
  100.         PUSH  DI
  101.         LDS   DI,CS:[HandleTable]
  102.         MOV   CL,[DI+19]               ; Remember contents of last handle slot
  103.         MOV   CS:[SaveLastDCB],CL
  104.         MOV   CS:[SaveFunction],AH     ; Save function code for later
  105.  
  106.         CMP   AH,3EH                   ; Check for DOS functions that pass a handle
  107.         JB    CallOldInt21
  108.  
  109.         CMP   AH,40H                   ; Convert functions $3E..$40 (Close,Read,Write)
  110.         JBE   ConvertDCB
  111.  
  112.         CMP   AH,42H                   ; Convert function $42 (Seek)
  113.         JE    ConvertDCB
  114.  
  115.         CMP   AH,44H                   ; Convert function $44..$46 (IOCTL,DUP,FORCEDUP)
  116.         JB    CallOldInt21
  117.  
  118.         CMP   AH,46H
  119.         JBE   ConvertDCB
  120.  
  121.         CMP   AH,57H                   ; Convert function $57 (File time/date)
  122.         JE    ConvertDCB
  123.  
  124.         CMP   AH,5CH                   ; Convert function $5C (Lock/Unlock)
  125.         JE    ConvertDCB
  126.  
  127.         CMP   AH,68H                   ; Convert function $68 (Commit File)
  128.         JNE   CallOldInt21
  129.  
  130. ConvertDCB:
  131.         MOV   CS:[SaveHandle],BL       ; Save the original handle
  132.         CMP   BL,4                     ; Check for output to standard handle
  133.         JBE   CallOldInt21             ; Let calls with standard handle pass through
  134.  
  135.         SUB   BL,5                     ; Account for an offset of 5 in DCB number
  136.         MOV   [DI+19],BL               ; Stuff DCB into last handle slot
  137.         MOV   BL,19                    ; Use number of last handle slot
  138.  
  139. CallOldInt21:
  140.         POP   DI                       ; Restore the registers
  141.         POP   CX
  142.         POP   DS
  143.         PUSHF
  144.         CALL  CS:[IntVector]           ; Fake an INT21 to original handler
  145.         STI                            ; Allow interrupts
  146.  
  147.         PUSH  DS                       ; Setup pointer to handle table
  148.         PUSH  DI
  149.         PUSH  BX
  150.         LDS   DI,CS:[HandleTable]      ; Check if INT handler returned an error
  151.         JC    Done                     ; Possibly needs to goto CheckForHandle??
  152.  
  153.         MOV   BL,CS:[SaveFunction]     ; Check for return handles
  154.         CMP   BL,3CH                   ; Convert function $3C (Create)
  155.         JE    ConvertHandle
  156.         CMP   BL,3DH                   ; Convert function $3D (Open)
  157.         JE    ConvertHandle
  158.         CMP   BL,45H                   ; Convert function $45 (Dup)
  159.         JE    ConvertHandle
  160.         CMP   BL,5AH                   ; Convert function $5A (Create unique)
  161.         JE    ConvertHandle
  162.         CMP   BL,5BH                   ; Convert function $5B (Create new)
  163.         JE    ConvertHandle
  164.         CMP   BL,68H                   ; Convert function $68 (Commit file)
  165.         JNE   CheckForHandle
  166.  
  167. ConvertHandle:
  168.         MOV   BX,AX                    ; Use handle as offset into handle table
  169.         MOV   AL,0FFH                  ; Show the handle as unused
  170.         XCHG  AL,[DI+BX]               ; Return DCB as handle number
  171.         ADD   AL,5                     ; Use offset of 5 to avoid standard handles
  172.  
  173. CheckForHandle:
  174.         MOV   BL,CS:[SaveFunction]     ; Check for handles left in registers
  175.         CMP   BL,3FH                   ; Convert function $3F (Read)
  176.         JE    RestoreHandle
  177.         CMP   BL,40H                   ; Convert function $40 (Write)
  178.         JE    RestoreHandle
  179.         CMP   BL,42H                   ; Convert function $42 (Seek)
  180.         JE    RestoreHandle
  181.         CMP   BL,44H                   ; Convert function $44..$46 (IOCTL,DUP,FORCEDUP)
  182.         JB    Success
  183.         CMP   BL,46H
  184.         JBE   RestoreHandle
  185.         CMP   BL,57H                   ; Convert function $57 (File time/date)
  186.         JE    RestoreHandle
  187.         CMP   BL,5CH                   ; Convert function $5C (Lock/Unlock)
  188.         JNE   Success
  189.  
  190. RestoreHandle:
  191.         POP   BX
  192.         MOV   BL,CS:[SaveHandle]       ; Restore original handle in case calling
  193.         PUSH  BX                       ; program assumes BX unchanged
  194.  
  195. Success:
  196.         CLC                            ; Everything is fine so clear error flag
  197.  
  198. Done:
  199.         MOV   BL,CS:[SaveLastDCB]      ; Restore contents of last handle slot
  200.         MOV   [DI+19],BL
  201.         POP   BX
  202.         POP   DI
  203.         POP   DS
  204. ReturnToTurbo:
  205.         RET   2                        ; Return to the calling program and cleanup stack
  206.  
  207. ExtendHandler ENDP
  208.  
  209. CSEG    ENDS
  210.  
  211.         END
  212.